from django.contrib import admin

from permissions.models import Component, Route, Api, FileTag
from permissions.models import GenericPermissions, PermissionGroup, PermissionUser


@admin.register(Component)
class ButtonAdmin(admin.ModelAdmin):
    list_display = ('name', 'code')
    search_fields = ('name', 'code')


@admin.register(Route)
class RouteAdmin(admin.ModelAdmin):
    list_display = ('name', 'code', 'path')
    search_fields = ('name', 'code', 'path')


@admin.register(Api)
class ApiAdmin(admin.ModelAdmin):
    list_display = ('name', 'code', 'path', 'method')
    search_fields = ('name', 'code', 'path', 'method')


@admin.register(FileTag)
class FileTagAdmin(admin.ModelAdmin):
    list_display = ('name', 'code')
    search_fields = ('name', 'code')


@admin.register(GenericPermissions)
class GenericPermissionsAdmin(admin.ModelAdmin):
    list_display = ('content_type', 'object_id', 'description',)
    search_fields = ('content_type', 'object_id', 'description',)


@admin.register(PermissionGroup)
class PermissionGroupAdmin(admin.ModelAdmin):
    list_display = ('name',)
    fields = ('name', 'gp')
    filter_horizontal = ('gp',)
    readonly_fields = ('name',)


@admin.register(PermissionUser)
class PermissionUserAdmin(admin.ModelAdmin):
    list_display = ('username', 'first_name', 'last_name',)
    fields = ('username', 'first_name', 'last_name', 'gp')
    filter_horizontal = ('gp',)
    readonly_fields = ('username', 'first_name', 'last_name')
